home *** CD-ROM | disk | FTP | other *** search
/ Delphi Developer's Kit 1996 / Delphi Developer's Kit 1996.iso / power / lingua / lingua.pas < prev    next >
Pascal/Delphi Source File  |  1995-12-22  |  24KB  |  826 lines

  1. unit Lingua;
  2. (***************************************************************************)
  3. (*                                                                         *)
  4. (*   #####    #####     #####   #####    #####    ####    ######  #######  *)
  5. (*  #        #     #   #          #     #        #    #   #          #     *)
  6. (*  #        #     #   #  ###     #      ####    #    #   ###        #     *)
  7. (*  #        #     #   #    #     #          #   #    #   #          #     *)
  8. (*   #####    #####     #####   #####   #####     ####    #          #     *)
  9. (*                                                                         *)
  10. (***************************************************************************)
  11. {
  12.  (c) 1995 Cogisoft
  13.  This component is FREE distribution. Use it for your own utilization.
  14.  But you can't sell an application, using this component, without the
  15.  authorization of Cogisoft.
  16.  
  17.  COGISOFT,H⌠tel de MΘziΦres,19 rue Michel Le Comte,75003 PARIS,FRANCE
  18.  Tel:(1)40-65-04-04, FAX:(1)42-72-27-87
  19.  
  20.  NO CODING !!!
  21.  Jerome VOLLET, CompuServe : 100560,3342
  22. }
  23. interface
  24.  
  25. uses
  26.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  27.   Forms, Dialogs, Grids, Outline, DB, DBTables, DsgnIntf, DBGrids,
  28.   TypInfo, StdCtrls;
  29.  
  30. const
  31.     CM_REFRESHTRANSLATION = CM_BASE+1000;
  32.     CM_LINGUACREATED = CM_BASE+1001;
  33.  
  34. type
  35.   TCallbackUpdateProperty = procedure( var Value : string ) of object;
  36.     TCallbackScanProperties = procedure( Component : TComponent; PropInfo : PPropInfo ) of object;
  37.  
  38.   TLingua = class(TComponent)
  39.   private
  40.     { Private declarations }
  41.   protected
  42.     { Protected declarations }
  43.         CallbackUpdateProperty : TCallbackUpdateProperty;
  44.         CallbackScanProperties : TCallbackScanProperties;
  45.         FCheck : string;
  46.         FTest : Boolean;
  47.         FOldCookie : string;
  48.     FCookie : string;
  49.     FDatabaseName : TFileName;
  50.         FfmNewKeyword : TForm;
  51.     FLanguage : string;
  52.     FLang_Id : Integer;
  53.     FListComponent : TList;
  54.     FListProperties : TList;
  55.     FNewWordPrompt : boolean;
  56.         FTableLangList : TTable;
  57.         FTableLangWord : TTable;
  58.         FTableLang : TTable;
  59.         FTranslating : Boolean;
  60.       FHandle : HWnd;
  61.         procedure AddComponents;
  62.     function InternalGetWord( Word_Name : string ) : string;
  63.         procedure InternalTranslateProperty( Component : TComponent; PropInfo : PPropInfo );
  64.         procedure UpdateStrProperty( Component : TComponent; PropInfo : PPropInfo );
  65.         procedure ScanProperties( Component : TComponent; TypeKinds: TTypeKinds );
  66.         procedure TranslatePropertyCallback( var Value : string );
  67.         procedure AddCookie2PropertyCallback( var Value : string );
  68.         procedure InsertPropertyCallback( Component : TComponent; PropInfo : PPropInfo );
  69.         procedure UpdateCookieCallback( var Value : string );
  70.  
  71.         procedure Notification( AComponent : TComponent; Operation : TOperation ); override;
  72.     procedure RefreshTranslation;
  73.         procedure SetCheck( Value : string );
  74.         procedure SetCookie( Value : string );
  75.     procedure SetDatabaseName(const Value: TFileName);
  76.     procedure SetLanguage( Value : string );
  77.         procedure WndProc(var Msg : TMessage);
  78.   public
  79.     { Public declarations }
  80.         constructor Create( AOwner : TComponent ); override;
  81.     destructor Destroy; override;
  82.         procedure InsertNewLanguage( Lang_Name : string );
  83.         procedure InsertNewWord( Word_Name, Word_Trans : string );
  84.     function EditNewWord( Word_Name : string ):Boolean;
  85.         function EditNewLanguage:Boolean;
  86.         procedure EditUpdateCookie;
  87.     function GetWordWithCookie( Word_Name : string ) : string;
  88.     function GetWord( Word_Name : string ) : string;
  89.         procedure AddCookie2Property( Component : TComponent; PropertyName : string );
  90.         procedure TranslateProperty( Component : TComponent; PropertyName : string );
  91.     procedure TranslateComponent( Component : TComponent );
  92.         procedure TranslateForm( Form : TForm );
  93.     procedure Translate;
  94.  
  95.         property Handle : HWnd read FHandle;
  96.         property TableLangList : TTable read FTableLangList;
  97.   published
  98.     { Published declarations }
  99.     property Check : string read FCheck write SetCheck;
  100.         property Cookie : string read FCookie write SetCookie;
  101.     property DatabaseName : TFileName read FDatabaseName write SetDatabaseName;
  102.     property Language : string read FLanguage write SetLanguage;
  103.     property NewWordPrompt : Boolean read FNewWordPrompt write FNewWordPrompt;
  104.   end;
  105.  
  106.     TPropertyItem = class
  107.   public
  108.       Component : TComponent;
  109.     PropertyName : string;
  110.     PropertyValue : string;
  111.       constructor Create( c : TComponent; pn, pv : string );
  112.   end;
  113.  
  114. procedure Register;
  115.  
  116. implementation
  117.  
  118. uses DBConsts, Newkwd, NewLang, UpCookie;
  119.  
  120. constructor TLingua.Create( AOwner : TComponent );
  121. begin
  122.   FListComponent := TList.Create;
  123.   FHandle := AllocateHWnd(WndProc);
  124.   PostMessage( Handle, CM_LINGUACREATED, 0, 0 );
  125.   inherited Create( AOwner );
  126.     FTest := False;
  127.     FLang_Id := 0;
  128.   FLanguage := '';
  129.   FDatabaseName := '';
  130.     FTableLangList := TTable.Create( TComponent( Self ) );
  131.     FTableLangList.TableName := 'LANGLIST';
  132.     FTableLangWord := TTable.Create( TComponent( Self ) );
  133.     FTableLangWord.TableName := 'LANGWORD';
  134.     FTableLang := TTable.Create( TComponent( Self ) );
  135.     FTableLang.TableName := 'LANG';
  136.   Cookie := '##';
  137.   NewWordPrompt := True;
  138.   Check := '';
  139.   FfmNewKeyWord := nil;
  140.     FTranslating := False;
  141. end;
  142.  
  143. destructor TLingua.Destroy;
  144. begin
  145.   DeallocateHWnd(FHandle);
  146.     if FTableLangList.Active then FTableLang.Close;
  147.     if FTableLangWord.Active then FTableLang.Close;
  148.     if FTableLang.Active then FTableLang.Close;
  149.   FListComponent.Free;
  150.   inherited Destroy;
  151.     if Assigned( FfmNewKeyword ) then FfmNewKeyword.Free;
  152. end;
  153.  
  154. procedure TLingua.AddComponents;
  155. var
  156.     i    : Integer;
  157.   Form : TForm;
  158. begin
  159.     Form := GetParentForm( Self.Owner as TControl );
  160.     if Form = nil then
  161.     raise Exception.Create( 'Form nil' );
  162.      FListComponent.Add( Form );
  163.     for i:=0 to Form.ComponentCount-1 do
  164.     begin
  165.       FListComponent.Add( Form.Components[ i ] );
  166.   end;
  167.   if not FTranslating then
  168.          PostMessage( Handle, CM_REFRESHTRANSLATION, 0, 0 );
  169. end;
  170.  
  171. procedure TLingua.WndProc(var Msg: TMessage);
  172. begin
  173.   with Msg do
  174.         case Msg of
  175.         CM_LINGUACREATED:
  176.         if not (csDesigning in ComponentState) then
  177.         begin
  178.                     AddComponents;
  179.           Exit;
  180.           try
  181.             Translate;
  182.           except
  183.               Application.HandleException( Self );
  184.           end;
  185.         end;
  186.         CM_REFRESHTRANSLATION:
  187.           if not FTranslating then
  188.             begin
  189.           try
  190.                 RefreshTranslation;
  191.               except
  192.                 Application.HandleException(Self);
  193.               end
  194.           end
  195.     else
  196.       Result := DefWindowProc(Handle, Msg, wParam, lParam);
  197.     end;
  198. end;
  199.  
  200. procedure TLingua.Notification( AComponent : TComponent; Operation : TOperation );
  201. begin
  202.   inherited Notification( AComponent, Operation );
  203.   case Operation of
  204.     opInsert:
  205.     begin
  206.         if not (csDesigning in ComponentState) then
  207.           FListComponent.Add( AComponent );
  208.       if not FTranslating then
  209.           PostMessage( Handle, CM_REFRESHTRANSLATION, 0, 0 );
  210.     end;
  211.     opRemove:
  212.       begin
  213.       end;
  214.   end;
  215. end;
  216.  
  217. procedure TLingua.RefreshTranslation;
  218. var
  219.     i : integer;
  220. begin
  221.     if FlistComponent.Count = 0 then Exit;
  222.   for i:=0 to FListComponent.Count-1 do
  223.       TranslateComponent( TComponent( FListComponent[ i ] ) );
  224.   FListComponent.Clear;
  225. end;
  226.  
  227. procedure TLingua.SetCheck( Value : string );
  228. begin
  229.     FCheck := 'Click on ...';
  230. end;
  231.  
  232. procedure TLingua.UpdateCookieCallback( var Value : string );
  233. begin
  234.   if         (length( Value )>length( FOldCookie ))
  235.       and (CompareText( FOldCookie, Copy( Value, 1, length( FOldCookie ) ))=0) then
  236.         Value := Cookie+Copy( Value, Length(FOldCookie)+1, Length(Value)-length( FOldCookie ));
  237. end;
  238.  
  239. procedure TLingua.SetCookie( Value : string );
  240. var
  241.     Form : TForm;
  242.   i : Integer;
  243. begin
  244.     if Value = FCookie then Exit;
  245.     FOldCookie := FCookie;
  246.   FCookie := Value;
  247.   if FOldCookie = '' then Exit;
  248.     Form := GetParentForm( Self.Owner as TControl );
  249.   if Form = nil then Exit;
  250.     CallbackScanProperties := UpdateStrProperty;
  251.     CallbackUpdateProperty := UpdateCookieCallback;
  252.     try
  253.         ScanProperties( Form, [tkString] );
  254.         for i:=0 to Form.ComponentCount-1 do
  255.         if not (Form.Components[ i ] is TLingua) then
  256.               ScanProperties( Form.Components[ i ], [tkString] );
  257.     finally
  258.       CallbackScanProperties := nil;
  259.       CallbackUpdateProperty := nil;
  260.   end;
  261. end;
  262.  
  263. procedure TLingua.SetDatabaseName(const Value: TFileName);
  264. begin
  265.     try
  266.     FTableLangList.Close;
  267.     FTableLangWord.Close;
  268.     FTableLang.Close;
  269.     FTableLangList.DatabaseName := Value;
  270.     FTableLangList.IndexName := 'Lang_Name';
  271.     FTableLangList.Open;
  272.         FTableLangList.First;
  273.     FTableLangWord.DatabaseName := Value;
  274.     FTableLangWord.IndexName := 'Word_Name';
  275.     FTableLangWord.Open;
  276.     FTableLang.DatabaseName := Value;
  277.     FTableLang.Open;
  278.         if FtableLangList.RecordCount = 0 then
  279.             EditNewLanguage;
  280.         if FTableLangList.RecordCount > 0 then
  281.             Language := FTableLangList.FieldByName( 'Lang_Name' ).asString;
  282.     except on E:EDatabaseError do
  283.      begin
  284.         ShowMessage(  'You need to choose the alias wich points on'+#13#10+
  285.                                 'tables LANGLIST, LANGWORD and LANG.'+#13#10+#13#10+
  286.                   'If this alias does not exist, you need to create it !!!' );
  287.     exit;
  288.   end;
  289.   end;
  290.   FDatabaseName := Value;
  291. end;
  292.  
  293. procedure TLingua.SetLanguage( Value : string );
  294. begin
  295.     FTableLangList.SetKey;
  296.   FTableLangList.FieldByName( 'Lang_Name' ).asString := Value;
  297.   if not FTableLangList.GotoKey then
  298.     raise Exception.Create( 'Can''t locate : '+Value );
  299.     FLang_Id := FTableLangList.FieldByName( 'Lang_Id' ).asInteger;
  300.   FLanguage := Value;
  301.  
  302.     if Assigned( FfmNewKeyword ) then FfmNewKeyword.Free;
  303.      FfmNewKeyword := TfmNewKeyword.Create( nil );
  304.      TranslateForm( FfmNewKeyword );
  305. end;
  306.  
  307. function TLingua.GetWordWithCookie( Word_Name : string ) : string;
  308. begin
  309.     Result := '';
  310.   if (length( Word_Name )>length( Cookie )) and (CompareText( Cookie, Copy( Word_Name, 1, length( Cookie ) ))=0) then
  311.     begin
  312.       try
  313.       Result := GetWord( Copy( Word_Name, length(Cookie)+1, length(Word_Name)-length(Cookie) ) );
  314.     finally
  315.     end
  316.   end else
  317.       raise Exception.Create( 'No cookie found' );
  318. end;
  319.  
  320. function TLingua.InternalGetWord( Word_Name : string ) : string;
  321. var
  322.     Word_Id :    Integer;
  323. begin
  324.     Result := '';
  325.     FTableLangWord.SetKey;
  326.   FTableLangWord.FieldByName( 'Word_Name' ).asString := Word_Name;
  327.   if not FTableLangWord.GotoKey then
  328.     raise Exception.Create( 'Can''t locate : '+Word_Name );
  329.     Word_Id := FTableLangWord.FieldByName( 'Word_Id' ).asInteger;
  330.     FTableLang.SetKey;
  331.   FTableLang.FieldByName( 'Word_Id' ).asInteger := Word_Id;
  332.   FTableLang.FieldByName( 'Lang_Id' ).asInteger := FLang_Id;
  333.     if not FTableLang.GotoKey then
  334.     raise Exception.Create( 'Can''t locate word in table LANG' );
  335.     Result := FTableLang.FieldByName( 'Word_Trans' ).asString;
  336. end;
  337.  
  338. function TLingua.GetWord( Word_Name : string ) : string;
  339. begin
  340.     Result := '';
  341.     try
  342.       Result := InternalGetWord( Word_Name );
  343.   except
  344.     if NewWordPrompt then
  345.     begin
  346.       try
  347.         if EditNewWord( Word_Name ) then
  348.           Result := GetWord( Word_Name )
  349.         else
  350.           Result := Word_Name;
  351.       finally
  352.       end;
  353.     end else
  354.         Result := Word_Name;
  355.   end;
  356. end;
  357.  
  358. procedure TLingua.UpdateStrProperty( Component : TComponent; PropInfo : PPropInfo );
  359. var
  360.     OldValue, Value : string;
  361. begin
  362.   Value := GetStrProp( Component, PropInfo );
  363.     OldValue := Value;
  364.     if Assigned( CallbackUpdateProperty ) then
  365.       CallbackUpdateProperty( Value );
  366.   if not FTest and (Value <> OldValue) then SetStrProp( Component, PropInfo, Value );
  367. end;
  368.  
  369. procedure TLingua.InternalTranslateProperty( Component : TComponent; PropInfo : PPropInfo );
  370. begin
  371.     if Language = '' then Exit;
  372.     CallbackUpdateProperty := TranslatePropertyCallback;
  373.     UpdateStrProperty( Component, PropInfo );
  374.     CallbackUpdateProperty := nil;
  375. end;
  376.  
  377. procedure TLingua.TranslateProperty( Component : TComponent; PropertyName : string );
  378. var
  379.   PropInfo : PPropInfo;
  380. begin
  381.     if Language = '' then Exit;
  382.   PropInfo := GetPropInfo( Component.ClassInfo, PropertyName );
  383.   if PropInfo = nil then Exit;
  384.   if PropInfo^.PropType^.Kind = tkString then
  385.   begin
  386.         CallbackUpdateProperty := TranslatePropertyCallback;
  387.         UpdateStrProperty( Component, PropInfo );
  388.         CallbackUpdateProperty := nil;
  389.   end;
  390. end;
  391.  
  392. procedure TLingua.AddCookie2Property( Component : TComponent; PropertyName : string );
  393. var
  394.   PropInfo : PPropInfo;
  395. begin
  396.   PropInfo := GetPropInfo( Component.ClassInfo, PropertyName );
  397.   if PropInfo = nil then Exit;
  398.   if PropInfo^.PropType^.Kind = tkString then
  399.   begin
  400.         CallbackUpdateProperty := AddCookie2PropertyCallback;
  401.         UpdateStrProperty( Component, PropInfo );
  402.         CallbackUpdateProperty := nil;
  403.   end;
  404. end;
  405.  
  406. procedure TLingua.TranslatePropertyCallback( var Value : string );
  407. var
  408.     Word_Name : string;
  409. begin
  410.   if (length( Value )>length( Cookie )) and (CompareText( Cookie, Copy( Value, 1, length( Cookie ) ))=0) then
  411.   begin
  412.     Word_Name := Copy( Value, length(Cookie)+1, length(Value)-length(Cookie) );
  413.     Value := GetWord( Word_Name );
  414.   end;
  415. end;
  416.  
  417. procedure TLingua.AddCookie2PropertyCallback( var Value : string );
  418. var
  419.     Word_Name : string;
  420. begin
  421.   if         (length( Value )>length( Cookie ))
  422.       and (CompareText( Cookie, Copy( Value, 1, length( Cookie ) ))=0) then
  423.     { Cookie already present }
  424.       Exit;
  425.   Value := Cookie+Value;
  426. end;
  427.  
  428. procedure TLingua.ScanProperties( Component : TComponent; TypeKinds: TTypeKinds );
  429. var
  430.     j : Integer;
  431.   FCount, FSize : integer;
  432.   FList : PPropList;
  433. begin
  434.   FCount := GetPropList(Component.ClassInfo, TypeKinds, nil);
  435.   FSize := FCount * SizeOf(Pointer);
  436.   GetMem(FList, FSize);
  437.   GetPropList(Component.ClassInfo, TypeKinds, FList);
  438.  
  439.   for j:=0 to FCount-1 do
  440.   begin
  441.         if Assigned ( CallbackScanProperties ) then
  442.         CallbackScanProperties( Component, FList^[ j ] );
  443.   end;
  444.   FreeMem( FList, FSize );
  445. end;
  446.  
  447. procedure TLingua.TranslateComponent( Component : TComponent );
  448. begin
  449.     if Language = '' then Exit;
  450.     CallbackScanProperties := InternalTranslateProperty;
  451.     ScanProperties( Component, [ tkString ] );
  452.     CallbackScanProperties := nil;
  453. end;
  454.  
  455.  
  456. procedure TLingua.TranslateForm( Form : TForm );
  457. var
  458.     i    : Integer;
  459.   Component : TComponent;
  460. begin
  461.     if Language = '' then Exit;
  462.     TranslateComponent( Form );
  463.     for i:=0 to Form.ComponentCount-1 do
  464.     begin
  465.       Component := Form.Components[ i ];
  466.     TranslateComponent( Component );
  467.   end;
  468. end;
  469.  
  470. procedure TLingua.Translate;
  471. var
  472.     Form     : TForm;
  473. begin
  474.     if Language = '' then Exit;
  475.     Form := GetParentForm( Self.Owner as TControl );
  476.     if Form = nil then
  477.     raise Exception.Create( 'Form nil' );
  478.   TranslateForm( Form );
  479. end;
  480.  
  481. procedure TLingua.InsertNewLanguage( Lang_Name : string );
  482.  
  483.   procedure InsertLangName( Lang_Name : string );
  484.   begin
  485.         FTableLangList.Insert;
  486.     FTableLangList.FieldByName( 'Lang_Name' ).AsString := Lang_Name;
  487.         FTableLangList.Post;
  488.   end;
  489.  
  490. begin
  491.     { look for an already existing language }
  492.   FTableLangList.SetKey;
  493.   FTableLangList.FieldByName( 'Lang_Name' ).AsString := Lang_Name;
  494.   if not FTableLangList.GotoKey then
  495.   begin
  496.         InsertLangName( Lang_Name );
  497.     end else begin
  498.       raise Exception.Create( 'Language '+Lang_Name+' already exist !!!' );
  499.     end;
  500. end;
  501.  
  502. procedure TLingua.InsertNewWord( Word_Name, Word_Trans : string );
  503. var
  504.     Word_Id : LongInt;
  505.  
  506.   procedure InsertWordName( Word_Name : string );
  507.   begin
  508.         FTableLangWord.Insert;
  509.     FTableLangWord.FieldByName( 'Word_Name' ).AsString := Word_Name;
  510.         FTableLangWord.Post;
  511.     Word_Id := FTableLangWord.FieldByName( 'Word_Id' ).AsInteger;
  512.   end;
  513.  
  514.   procedure InsertWordTrans( Word_Id, Lang_Id : LongInt; Word_Trans : string );
  515.   begin
  516.         FTableLang.Insert;
  517.     FTableLang.FieldByName( 'Word_Id' ).AsInteger := Word_Id;
  518.     FTableLang.FieldByName( 'Lang_Id' ).AsInteger := Lang_Id;
  519.     FTableLang.FieldByName( 'Word_Trans' ).AsString := Word_Trans;
  520.         FTableLang.Post;
  521.   end;
  522.  
  523. begin
  524.     { look for an already existing keyword }
  525.   FTableLangWord.SetKey;
  526.   FTableLangWord.FieldByName( 'Word_Name' ).asString := Word_Name;
  527.   if not FTableLangWord.GotoKey then
  528.   begin
  529.         InsertWordName( Word_Name );
  530.     InsertWordTrans( Word_Id, FLang_Id, Word_Trans );
  531.     end else begin
  532.       Word_Id := FTableLangWord.FieldByName( 'Word_Id' ).asInteger;
  533.       FTableLang.SetKey;
  534.       FTableLang.FieldByName( 'Word_Id' ).asInteger := Word_Id;
  535.       FTableLang.FieldByName( 'Lang_Id' ).asInteger := FLang_Id;
  536.       if not FTableLang.GotoKey then
  537.     begin
  538.             InsertWordTrans( Word_Id, FLang_Id, Word_Trans );
  539.     end else begin
  540.         FTableLang.Edit;
  541.       FTableLang.FieldByName( 'Word_Trans' ).asString := Word_Trans;
  542.       FTableLang.Post;
  543.     end;
  544.     end;
  545. end;
  546.  
  547. function TLingua.EditNewWord( Word_Name : string ):Boolean;
  548. begin
  549.     Result := False;
  550.     if FTranslating then Exit;
  551.     FTranslating := True;
  552.   try
  553.         with FfmNewKeyword as TfmNewKeyword do
  554.     begin
  555.         EdLanguage.Text := Language;
  556.         EdKeyword.Text := Word_Name;
  557.       EdTranslation.Text := '';
  558.             if ShowModal <> mrOk then
  559.           Exit;
  560.         end;
  561.         InsertNewWord( Word_Name, ( FfmNewKeyword as TfmNewKeyword ).EdTranslation.Text );
  562.     Result := True;
  563.   finally
  564.         FTranslating := False;
  565.   end;
  566. end;
  567.  
  568. function TLingua.EditNewLanguage:Boolean;
  569. var
  570.     fmNewLanguage : TfmNewLanguage;
  571. begin
  572.     Result := False;
  573.   fmNewLanguage := TfmNewLanguage.Create( nil );
  574.   TranslateForm( fmNewLanguage );
  575.   try
  576.     with fmNewLanguage do
  577.     begin
  578.       EdLanguage.Text := '';
  579.       if ShowModal = mrOk then
  580.       try
  581.         InsertNewLanguage( EdLanguage.Text );
  582.             Language := EdLanguage.Text;
  583.             Result := True;
  584.       except on E:Exception do
  585.         ShowMessage( E.Message );
  586.       end;
  587.     end;
  588.   finally
  589.     fmNewLanguage.Free;
  590.   end;
  591. end;
  592.  
  593.  
  594.  
  595. constructor TPropertyItem.Create( c : TComponent; pn, pv : string );
  596. begin
  597.     Component := c;
  598.   PropertyName := pn;
  599.   PropertyValue := pv;
  600. end;
  601.  
  602. procedure TLingua.InsertPropertyCallback( Component : TComponent; PropInfo : PPropInfo );
  603. var
  604.     Value : string;
  605. begin
  606.     if PropInfo^.Name = 'Name' then Exit;
  607.   Value := GetStrProp( Component, PropInfo );
  608.     FListProperties.Add( TPropertyItem.Create( Component, PropInfo^.Name, Value ) );
  609. end;
  610.  
  611. procedure TLingua.EditUpdateCookie;
  612. var
  613.     i    : Integer;
  614.   Component : TComponent;
  615.   Form : TForm;
  616.   fmUpdateCookie : TfmUpdateCookie;
  617.   item : TPropertyItem;
  618.   mr : Integer;
  619.  
  620.     procedure InitfmUpdateCookie;
  621.     var
  622.       i : Integer;
  623.     begin
  624.     fmUpdateCookie := TfmUpdateCookie.Create( nil );
  625.     TranslateForm( fmUpdateCookie );
  626.     for i:=0 to FListProperties.Count-1 do
  627.     begin
  628.       item := TPropertyItem(FListProperties[ i ]);
  629.       with TCheckbox.Create( fmUpdateCookie.sbxProperties ) do
  630.       begin
  631.         Parent := fmUpdateCookie.sbxProperties;
  632.         Top := 5+i*20;
  633.         Left := 10;
  634.         Width := 500;
  635.         Caption := item.Component.Name+'.'+item.PropertyName+' = '+item.PropertyValue;
  636.                 if     (    (length( item.PropertyValue )>length( Cookie ))
  637.                 and (CompareText( Cookie, Copy( item.PropertyValue, 1, length( Cookie ) ))=0) ) then
  638.         begin
  639.             State := cbGrayed;
  640.           Enabled := False;
  641.         end
  642.         else if ((item.PropertyName = 'Caption') or (item.PropertyName = 'Hint'))
  643.                and (Length( item.PropertyValue ) > 0) then
  644.                     State := cbChecked;
  645.       end;
  646.     end;
  647.   end;
  648.  
  649.     procedure UpdateCookie;
  650.     var
  651.       i : Integer;
  652.   begin
  653.     for i:=0 to fmUpdateCookie.sbxProperties.ComponentCount-1 do
  654.         if (fmUpdateCookie.sbxProperties.Components[ i ] as TCheckbox).State = cbChecked then
  655.         begin
  656.           item := TPropertyItem( FListProperties[i] );
  657.           AddCookie2Property( item.Component, item.PropertyName );
  658.         end;
  659.     end;
  660.  
  661. begin
  662.     Form := GetParentForm( Self.Owner as TControl );
  663.   if Form = nil then Exit;
  664.     FListProperties := TList.Create;
  665.     try
  666.         CallbackScanProperties := InsertPropertyCallback;
  667.         ScanProperties( Form, [tkString] );
  668.  
  669.         for i:=0 to Form.ComponentCount-1 do
  670.         if not (Form.Components[ i ] is TLingua) then
  671.               ScanProperties( Form.Components[ i ], [tkString] );
  672.  
  673.       CallbackScanProperties := nil;
  674.         try
  675.             InitfmUpdateCookie;
  676.       mr := fmUpdateCookie.ShowModal;
  677.       if mr = mrOk then
  678.           UpdateCookie;
  679.     finally
  680.         fmUpdateCookie.Free;
  681.     end;
  682.     finally
  683.          for i:=0 to FListProperties.Count-1 do
  684.         TPropertyItem(FListProperties[ i ]).Free;
  685.     FListProperties.Free;
  686.      end;
  687.     if mr <> mrOk then
  688.       Exit;
  689.  
  690.     FTest := True;
  691.   try
  692.         Translate;
  693.     ShowMessage( 'Check is ok' );
  694.   finally
  695.         FTest := False;
  696.   end;
  697. end;
  698.  
  699.  
  700. { TDatabaseNameProperty }
  701.  
  702. type
  703.   TDatabaseNameProperty = class(TStringProperty)
  704.   public
  705.         function GetAttributes: TPropertyAttributes; override;
  706.         procedure GetValues(Proc: TGetStrProc); override;
  707.   end;
  708.  
  709. function TDatabaseNameProperty.GetAttributes: TPropertyAttributes;
  710. begin
  711.       Result := [paValueList, paSortList, paMultiSelect];
  712. end;
  713.  
  714. procedure TDatabaseNameProperty.GetValues(Proc: TGetStrProc);
  715. var
  716.       I: Integer;
  717.       Values: TStringList;
  718. begin
  719.       Values := TStringList.Create;
  720.       try
  721.         Session.GetDatabaseNames(Values);
  722.         for I := 0 to Values.Count - 1 do Proc(Values[I]);
  723.       finally
  724.         Values.Free;
  725.       end;
  726. end;
  727.  
  728. type
  729.   TLanguageProperty = class(TStringProperty)
  730.   public
  731.         function GetAttributes: TPropertyAttributes; override;
  732.         procedure GetValues(Proc: TGetStrProc); override;
  733.   end;
  734.  
  735. function TLanguageProperty.GetAttributes: TPropertyAttributes;
  736. begin
  737.       Result := [paValueList, paSortList, paMultiSelect];
  738. end;
  739.  
  740. procedure TLanguageProperty.GetValues(Proc: TGetStrProc);
  741. var
  742.   traductor : TLingua;
  743.     table    : TTable;
  744. begin
  745.     traductor := GetComponent( 0 ) as TLingua;
  746.     table := traductor.TableLangList;
  747.     try
  748.       table.First;
  749.     while not table.Eof do
  750.     begin
  751.         Proc( table.FieldByName( 'Lang_Name' ).asString );
  752.       table.Next;
  753.     end;
  754.     except on E:EDatabaseError do
  755.       ShowMessage( E.Message );
  756.     end;
  757. end;
  758.  
  759.  
  760. type
  761.   TCheckProperty = class(TStringProperty)
  762.     public
  763.       procedure Edit; override;
  764.       function GetAttributes:TPropertyAttributes; override;
  765.   end;
  766.  
  767. procedure TCheckProperty.Edit;
  768. begin
  769.     ( GetComponent(0) as TLingua ).FTest := True;
  770.   try
  771.         ( GetComponent(0) as TLingua ).Translate;
  772.     ShowMessage( 'Check is Ok' );
  773.   finally
  774.         ( GetComponent(0) as TLingua ).FTest := False;
  775.   end;
  776. end;
  777.  
  778. function TCheckProperty.GetAttributes:TPropertyAttributes;
  779. begin
  780.     Result := [ paDialog ];
  781. end;
  782.  
  783. type
  784.     TLinguaEditor = class(TComponentEditor)
  785.         function GetVerbCount: Integer; override;
  786.         function GetVerb( Index : Integer ): string; override;
  787.     procedure Edit; override;
  788.     procedure ExecuteVerb( Index : Integer ); override;
  789.   end;
  790.  
  791. function TLinguaEditor.GetVerbCount : Integer;
  792. begin
  793.     Result := 2;
  794. end;
  795.  
  796. function TLinguaEditor.GetVerb( Index : Integer ):string;
  797. const
  798.     tab : array[ 0..1 ] of string = ( 'Add language', 'Update cookie' );
  799. begin
  800.     Result := tab[ Index ];
  801. end;
  802.  
  803. procedure TLinguaEditor.Edit;
  804. begin
  805.     ShowMessage( 'Next version ...' );
  806. end;
  807.  
  808. procedure TLinguaEditor.ExecuteVerb( Index : Integer );
  809. begin
  810.     case Index of
  811.         0 :    (Component as TLingua).EditNewLanguage;
  812.     1 : (Component as TLingua).EditUpdateCookie;
  813.   end;
  814. end;
  815.  
  816. procedure Register;
  817. begin
  818.   RegisterComponents('Samples', [TLingua]);
  819.   RegisterPropertyEditor(TypeInfo(TFileName), TLingua, 'DatabaseName', TDatabaseNameProperty);
  820.   RegisterPropertyEditor(TypeInfo(string), TLingua, 'Language', TLanguageProperty);
  821.   RegisterPropertyEditor(TypeInfo(string), TLingua, 'Check', TCheckProperty);
  822.   RegisterComponentEditor( TLingua, TLinguaEditor ); 
  823. end;
  824.  
  825. end.
  826.